const axios = require('../utils/request')

// 手机登入
const phoneLogin = (username, password) => {
  return axios.post('/login/cellphone', { phone: username, password: password })
}
// 二维码登入
function qrLogin () {
  const date = new Date()
  return new Promise((resolve, reject) => {
    axios.post(`/login/qr/key?${date.getTime()}`).then((res) => {
      // console.log(res.data.unikey,123)
      const key = res.data.unikey
      axios.post(`/login/qr/create?${date.getTime()}`, { key, qrimg: true }).then((res) => {
        resolve({
          qr: res.data,
          key
        })
      })
    })
  })
}

// 歌曲搜索
const search = (songName) => {
  return axios.get('/cloudsearch', { keywords: songName })
}
// 获取用户详情
const getUserinfo = (uid) => {
  return axios.get('/user/detail', { uid })
}
// 获取用户歌单
const getUserMusicMenu = (uid) => {
  return axios.get('/user/playlist', { uid })
}
// 获取歌单详情
const getMusicMuenDetails = (id) => {
  return axios.get('/playlist/detail', { id })
}
// 获取歌曲详情
const songDetail = (id) => {
  return axios.get('/song/detail', { ids: id })
}
// 获取歌词
const getSongLyr = (id) => {
  return axios.get('/lyric', { id })
}

// 获取排行榜单
const getToplist = () => {
  return axios.get('/toplist', {})
}
// 获取歌单列表
const getSongmenu = (id, limit = 1000000) => {
  return axios.get('/playlist/track/all', { id, limit })
}
// 获取搜索排行
const searchHot = () => {
  return axios.get('/search/hot/detail')
}
// 获取轮播图
const homeImg = () => {
  return axios.get('/banner')
}
module.exports = {
  songDetail,
  getSongLyr,
  getToplist,
  getSongmenu,
  phoneLogin,
  getUserinfo,
  getUserMusicMenu,
  getMusicMuenDetails,
  searchHot,
  homeImg,
  qrLogin,
  search
}
